{layout name="public/layout" /}
{include file='yxnavbar'}


<div class="main">
    {include file='../../plugin/lottery/template/web/lottery_common_nav'}
    {if $method == "chance_main"}
    <div class="panel panel-info">
        <div class="panel-heading">当前数量： {$page_total}</div>
        <div class="panel-body">
            <form id="myform" action="./index.php" method="get" class="form-horizontal" role="form">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="{$_P['m']}" />
                <input type="hidden" name="do" value="web" />
                <input type="hidden" name="r" value="lottery.chance.search" id="r" />
                <div class="form-group">
                    <label class="col-xs-1 col-sm-1 col-md-1 control-label">机会来源</label>
                    <div class="col-xs-11 col-sm-9 col-md-9">
                        <div class="btn-group">
                            {loop $type_list $row}
                            <a href="{php echo createWebUrlPlugin('lottery.chance.main',array('themeid'=>$themeid,'type'=>$row['type']));}" class="btn {if $type == $row['type']}btn-primary{else}btn-default{/if}">
                                {$row['title']}
                                <span style="color: #ff0000">{$row['total']}</span>
                            </a>
                            {/loop}
                        </div>
                    </div>
                    {if count($themelist)>1 }
                    <div class="col-xs-12 col-sm-2 col-md-2">
                        <select onchange="submitForm();" class="form-control" name="themeid">
                            {loop $themelist $row}
                            <option value="{$row['id']}" {if $themeid == $row['id'] }selected="selected"{/if}>{$row['id']} - {php echo mb_substr($row['title'],0,8,'utf-8');}</option>
                            {/loop}
                        </select>
                    </div>
                    {else}
                    <input type="hidden" name="themeid" value="{$themeid}" />
                    {/if}
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-1 control-label">更新时间</label>
                    <div class="col-sm-3 col-lg-3 col-md-3 col-xs-6">
<!--                        {php echo view_form_field_daterange('createtime', array('start' => $start_day, 'end' => $end_day));}-->
                        {php echo view_form_field_daterange('createtime', array('start'=>date('Y-m-d H:i:s',$starttime),'end'=>date('Y-m-d H:i:s',$endtime)), true);}
                    </div>

                </div>
                <div class="form-group clearfix">
                    <label class="col-xs-12 col-sm-3 col-md-1 control-label">关键字</label>
                    <div class="col-sm-4 col-xs-4 col-md-4">
                        <input class="form-control" name="search_data" placeholder="输入报名手机号、微信昵称、客资姓名" type="text" value="{$_P['search_data']}">
                    </div>
                    <div class="col-sm-3 col-lg-3 col-md-3 col-xs-6">
                        <button class="btn btn-primary"><i class="fa fa-search"></i> 搜索</button>
                        <input type="hidden" name="__token__" value="{$Request.token}"/>
                    </div>
                </div>
            </form>
        </div>
    </div>
    {/if}

    <div class="tab-content">
        <div class="panel panel-default">
            <div class="panel-body table-responsive">
                <table class="table table-hover">
                    <thead class="navbar-inner">
                    <tr>
                        <th style="width: 50px">序号</th>
                        <th style="width: 100px">昵称</th>
                        <th style="width: 100px">姓名/电话</th>
                        <th style="width: 100px">机会类型</th>
                        <th style="width: 100px">好友信息</th>
                        <th style="width: 100px">机会剩余</th>
                        <th style="width: 100px">机会操作</th>
                        <th style="width: 100px">更新时间</th>
                        <th style="width: 120px;text-align: right">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {loop $list $index $item}
                    <tr>
                        <td>{$item['c_id']}</td>
                        <td>
                            <img src="{php echo tomedia($item['avatar']);}" style="width: 28px;height: 28px;padding: 1px;">
                            <br>
                            {$item['nickname']}
                        </td>
                        <td>{$item['username']}<br/>{$item['mobile']}</td>
                        <td>
                            {if $item['type']=='system'}
                            <span class="label label-warning">抽奖扣除</span>
                            {elseif $item['type']=='no_sign_up'}
                            <span class="label label-success">未报名</span>
                            {elseif $item['type']=='self_order'}
                            <span class="label label-danger">用户下单</span>
                            {elseif $item['type']=='share_moments'}
                            <span class="label label-success">分享朋友圈</span>
                            {elseif $item['type']=='friend_order'}
                            <span class="label label-primary">好友订单-来自{$item['from_nickname']}</span>
                            {elseif $item['type']=='friend_view'}
                            <span class="label label-warning">好友到访-来自{$item['from_nickname']}</span>
                            {elseif $item['type']=='friend_help'}
                            <span class="label label-warning">好友助力-来自{$item['from_nickname']}</span>
                            {elseif $item['type']=='timeset'}
                            <span class="label label-info">定时奖励</span>
                            {elseif $item['type']=='lucky_star'}
                            <span class="label label-default">幸运星</span>
                            {elseif $item['type']=='system_add'}
                            <span class="label label-default">后台管理员增加</span>
                            {else}
                            {/if}
                        </td>
                        <td>
                            {if $item['type']=='friend_view' || $item['type']=='friend_help' || $item['type']=='friend_order'}
                            <img src="{php echo tomedia($item['from_avatar']);}" style="width: 40px;height: 40px;padding: 1px;"><br/>
                            {$item['from_nickname']}<br/>
                            {$item['from_uid']}<br/>
                            {else}
                            {/if}
                        </td>
                        <td>{$item['jihui']}</td>
                        <td>
                            {if $item['chance']>0}
                            <span class="label label-success">+{$item['chance']}</span>
                            {else}
                            <span class="label label-warning">{$item['chance']}</span>
                            {/if}
                        </td>

                        <td>
                            {$item['created_at']}
                        </td>
                        <td style="text-align: right">
                            {if $item['can_add']}
<!--                            <a class="btn btn-primary btn-sm" style="width: 35px"  data-type="edit" href="{php echo createWebUrl('comm',array('themeid'=>$themeid,'op'=>'edit','id'=>$item['fan_id']));}"-->
<!--                               data-edit-url="{php echo createWebUrlPlugin('lottery.chance.add');}"-->
<!--                               data-themeid="{$item['themeid']}" data-uid="{$item['uid']}"  title="给该用户增加机会" data-toggle="tooltip" data-placement="top"><i class="fa fa-heart"> </i></a>-->
                            {/if}
                            {if $item['chance']<1 && $item['type']!='friend_view'}
                            <a class="btn btn-danger btn-sm" style="width: 35px"  data-type="edit"
                               data-c_id = "{$item['c_id']}"
                               onclick="editFlagPrize(this)"
                               data-themeid="{$item['themeid']}" data-uid="{$item['uid']}"  title="手动录入中奖记录" data-toggle="tooltip" data-placement="top"><i class="fa fa-archive"> </i></a>
                            {/if}
                            {if $item['can_del']}
                            <a class="btn btn-danger btn-sm" style="width: 35px"  data-type="edit" data-edit-url="{php echo createWebUrlPlugin('lottery.chance.del');}" onclick="changeOrDelItem(this)"
                               data-themeid="{$item['themeid']}" data-cid="{$item['c_id']}" data-uid="{$item['uid']}"  title="删除用户抽奖机会记录" data-toggle="tooltip" data-placement="top"><i class="fa fa-trash-o"> </i></a>
                            {/if}
                        </td>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

{$pager}

<!--录入中奖奖品-->
<div class="edit" style="width: 40vw;height: 40vh;z-index:10;display:none;position: fixed;top: 50%;left: 50%;transform: translate(-50%,-50%) ">
    <div class="panel panel-info">
        <div class="panel-heading" style="background-color: #428bca;color: #f7f7f7;">
            <span>手动录入中奖记录</span>
            <span class="close_edit" style="float: right;">关闭</span>
        </div>
        <div class="panel-body">
            <form id ="myform2"  class="form-horizontal" role="form" style="margin: 0 auto;">
                <div class="form-group" style="margin-left: 0px;">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">选择奖项</label>
                    <div class="col-sm-10  col-xs-12">
                        {loop $can_edit_list  $row}
                        <label class="radio-inline">
                            <input name="p_id" type="radio" value="{$row['p_id']}" > {$row['title']}
                        </label>
                        {/loop}
                    </div>
                    <input type="hidden" id="add_c_id" name="add_c_id" value="">
                    <input type="hidden" id="add_uid" name="add_uid" value="">
                </div>

                <div class="form-group" id="sub_upload07" >
                    <div class=" col-sm-12">
                        <input  onclick="subEditFlagPrize()"  type="button" value="提交" class="btn btn-primary col-lg-2">
                    </div>
                </div>            </form>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(
        function (){

        }
    );
    function submitForm(){
        $("#r").val('lottery.chance.main');
        var form = document.getElementById("myform");
        form.submit();
    }
    function changeOrDelItem(e) {
        let uid = e.getAttribute("data-uid");
        let themeid = e.getAttribute("data-themeid");
        let cid = e.getAttribute("data-cid");
        let postUrl = e.getAttribute("data-edit-url");
        layer.msg('您确定给该用户删除抽奖机会吗？',{
            btn:['确定','取消'],
            yes:function (index) {
                $.ajax({
                    url:postUrl,
                    dataType:'json',
                    method:'post',
                    data: {uid:uid,themeid:themeid,cid:cid},
                    success:function (e) {
                        let res = e.result;
                        let status = res.status;
                        let msg = res.msg;
                        if (status!=1){
                            layer.msg(msg);
                        }else{
                            layer.msg(msg);
                        }
                        parent.location.reload();
                    },
                    fail:function (err) {
                        console.log(err)
                    }
                });
                // parent.location.reload();
            }
        });
    }

    //增加修改中奖记录
    function editFlagPrize(e) {
        let c_id = e.getAttribute("data-c_id");
        let uid = e.getAttribute("data-uid");
        $("#add_c_id").val(c_id);
        $("#add_uid").val(uid);
        $('.edit').show();
    }
    $('.close_edit').click(function () {
        $('.edit').hide();
    });

    //补录中奖记录
    function subEditFlagPrize()
    {
        let postUrl = "{php echo createWebUrlPlugin('lottery.chance.addLtFlagAndReduceChance',array('themeid'=>$themeid));}";
        let formData = $("#myform2").serialize();
        $.ajax({
            url:postUrl,
            dataType:'json',
            method:'post',
            data:formData,
            success:function (e) {
                let status = e.status;
                let result = e.result;
                if (status!=1){
                    layer.msg(result.msg)
                }else{
                    layer.msg(result.msg);
                }
                location.reload();
            },
            fail:function (err) {
                console.log(err)
            }
        })
    }
</script>
